{ "cells": [ { "cell_type": "markdown", "id": "a610a794-152f-46fc-8efd-5ed0fa972aa2", "metadata": {}, "source": [ "# ACS Demo" ] }, { "cell_type": "markdown", "id": "9802bb94-e3af-487b-8310-b1b4f3650786", "metadata": {}, "source": [ "## Introduction\n", "\n", "This notebook demonstrates how to load \n", "[US Census American Community Survey (ACS) 5-year data](https://www.census.gov/data/developers/data-sets/acs-5year.html)\n", "detailed tables and do demographic analysis on it. The process is very much parallel to how we loaded and used\n", "[US Census redistricting data](https://www.census.gov/programs-surveys/decennial-census/about/rdo.html)\n", "in the \n", "[SoMa DIS Demo](https://github.com/vengroff/censusdis/blob/main/notebooks/SoMa%20DIS%20Demo.ipynb)\n", "and \n", "[Seeing White](https://github.com/vengroff/censusdis/blob/main/notebooks/Seeing%20White.ipynb)\n", "notebooks." ] }, { "cell_type": "markdown", "id": "e1ebf22f-a1c5-4980-9bf4-b47d4f701feb", "metadata": {}, "source": [ "## Imports and configuration" ] }, { "cell_type": "code", "execution_count": 1, "id": "34c2e60c-afbd-4970-871f-706f7552ccd3", "metadata": { "tags": [] }, "outputs": [], "source": [ "import censusdis.data as ced\n", "from censusdis.datasets import ACS5\n", "from censusdis.states import NJ, NAMES_FROM_IDS\n", "\n", "import divintseg as dis" ] }, { "cell_type": "code", "execution_count": 2, "id": "ad2f0615-0d84-48c8-9bba-8342ea106c6c", "metadata": {}, "outputs": [], "source": [ "# Set your API key here.\n", "CENSUS_API_KEY = None" ] }, { "cell_type": "code", "execution_count": 3, "id": "e313a546-3b99-4021-af65-d87f739daee5", "metadata": {}, "outputs": [], "source": [ "YEAR = 2019\n", "DATASET = ACS5" ] }, { "cell_type": "code", "execution_count": 4, "id": "127ab269-260d-4c63-a22d-4798f9094e50", "metadata": {}, "outputs": [], "source": [ "# Feel free to try other states.\n", "STATE = NJ" ] }, { "cell_type": "code", "execution_count": 5, "id": "ec39d268-6c4b-4900-b038-c4f0aa36fd3d", "metadata": {}, "outputs": [], "source": [ "# A group of variables counting people by race and ethnicity.\n", "# See https://api.census.gov/data/2019/acs/acs5/groups/B03002.html\n", "GROUP = \"B03002\"" ] }, { "cell_type": "markdown", "id": "29900264-de82-4393-9248-7b3d15e7dac0", "metadata": {}, "source": [ "## Load the data and compute diversity and integration" ] }, { "cell_type": "code", "execution_count": 6, "id": "471dc72d-7288-44c0-b9e3-5974cfd7b343", "metadata": {}, "outputs": [], "source": [ "df_acs5 = ced.download(\n", " DATASET,\n", " YEAR,\n", " leaves_of_group=GROUP,\n", " state=STATE,\n", " block_group=\"*\",\n", " api_key=CENSUS_API_KEY,\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "065ab946-30e4-4015-a160-57cec26f4e40", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | STATE | \n", "COUNTY | \n", "TRACT | \n", "diversity | \n", "integration | \n", "
|---|---|---|---|---|---|
| 0 | \n", "34 | \n", "001 | \n", "000100 | \n", "0.799079 | \n", "0.742759 | \n", "
| 1 | \n", "34 | \n", "001 | \n", "000200 | \n", "0.774784 | \n", "0.701973 | \n", "
| 2 | \n", "34 | \n", "001 | \n", "000300 | \n", "0.781342 | \n", "0.726768 | \n", "
| 3 | \n", "34 | \n", "001 | \n", "000400 | \n", "0.765627 | \n", "0.687127 | \n", "
| 4 | \n", "34 | \n", "001 | \n", "000500 | \n", "0.695903 | \n", "0.685162 | \n", "